package com.soft.mainsite.module.sensitiveword.dto;

import com.soft.mainsite.module.sensitiveword.entity.SensitiveWord;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * SensitiveWordDto.java 此类用于敏感词dto
 *
 * @author:李昭阳
 * @date:2019/4/11 0011
 * @remark:
 */
@Data
public class SensitiveWordDto extends SensitiveWord{

    /**
     * 实体类列表转dto列表
     * @param entityList
     * @return
     */
    public static List<SensitiveWordDto> convertEntityToDtos(List<SensitiveWord> entityList) {
        List<SensitiveWordDto> dtoList = new ArrayList<>();
        for (SensitiveWord entity : entityList) {
            if (entity == null) {
                continue;
            }
            dtoList.add(convertEntityToDto(entity));
        }
        return dtoList;
    }

    /**
     * 实体类转dto
     * @param entity
     * @return
     */
    public static SensitiveWordDto convertEntityToDto(SensitiveWord entity) {
        SensitiveWordDto dto = new SensitiveWordDto();
        BeanUtils.copyProperties(entity, dto);
        return dto;
    }

    /**
     * dto列表转实体类列表
     * @param dtoList
     * @return
     */
    public static List<SensitiveWord> convertDtoToEntitys(List<SensitiveWordDto> dtoList){
        List<SensitiveWord> entityList = new ArrayList<>();
        for (SensitiveWordDto dto : dtoList) {
            if(dto == null){
                continue;
            }
            entityList.add(convertDtoToEntity(dto));
        }
        return entityList;
    }

    /**
     * dto转实体类
     * @param dto
     * @return
     */
    public static SensitiveWord convertDtoToEntity(SensitiveWordDto dto) {
        SensitiveWord entity = new SensitiveWord();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }
}
